﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">
    <!-- 下拉框 -->
    <link rel="stylesheet" href="static/ace/css/chosen.css"/>
    <!-- jsp文件头和头部 -->
    <%@ include file="../../system/index/top.jsp" %>
    <!-- 日期框 -->
    <link rel="stylesheet" href="static/ace/css/datepicker.css"/>
</head>
<body class="no-skin">

<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <!-- 检索  -->
                        <form action="setMeal/list" method="post" name="plantbaseForm" id="plantbaseForm">
                            <!-- 检索  -->
                            	<table style="margin-top:5px;">
							<tr>
								<td>
									<div class="nav-search">
									<span class="input-icon">
										<input class="nav-search-input" id="name" type="text" name="name" value="${pd.name}" placeholder="这里输入套餐名称" style="vertical-align:top;width: 190px;"/>
										<i class="ace-icon fa fa-search nav-search-icon"></i>
									</span>
									</div>
								</td>
								<td style="vertical-align:top;padding-left:2px;">
								 	<select class="chosen-select form-control" name="state" id="state" data-placeholder="状态" style="vertical-align:top;width: 120px;">
									<option value="">全部</option>
									<option value="01" <c:if test="${pd.state=='01'}">selected</c:if>>上架</option>
									<option value="00" <c:if test="${pd.state=='00'}">selected</c:if>>下架</option>
								  	</select>
								</td>
								<c:if test="${QX.cha == 1 }">
								<td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs" onclick="searchs();"  title="检索"><i id="nav-search-icon" class="ace-icon fa fa-search bigger-110 nav-search-icon blue"></i></a></td>
								</c:if>
								<%-- <c:if test="${QX.toExcel == 1 }"><td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs" onclick="toExcel();" title="导出到EXCEL"><i id="nav-search-icon" class="ace-icon fa fa-download bigger-110 nav-search-icon blue"></i></a></td></c:if> --%>
							</tr>
						</table>
                            <table id="simple-table"
                                   class="table table-striped table-bordered table-hover"
                                   style="margin-top: 5px;">
                                <thead>
                                <tr>
                                    <th class="center">ID</th>
                                    <th class="center">套餐期次</th>
                                    <th class="center">套餐名称</th>
                                    <th class="center">套餐功效</th>
                                    <th class="center">套餐价格</th>
                                    <th class="center">套餐库存</th>
                                    <th class="center">已售数量</th>
                                    <th class="center">权益周期 (月)</th>
                                    <th class="center">上架时间</th>
                                    <th class="center">下架时间</th>
                                    <th class="center">售馨状态</th>
                                    <th class="center">状态</th>
                                    <th class="center">操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                <!-- 开始循环 -->
                                <c:choose>
                                    <c:when test="${not empty mealList}">
                                        <c:if test="${QX.cha == 1 }">
                                            <c:forEach items="${mealList}" var="plantBase" varStatus="vs">
                                            <tr>
                                                    <td class='center' style="width: 50px;">${plantBase.id}</td>
                                                    <td class="center">${plantBase.time_id }</td>
                                                    <td class="center">${plantBase.name }</td>
                                                    <td class="center">${plantBase.package_efficacy}</td>
                                                    <td class="center">${plantBase.price }</td>
                                                    <td class="center">${plantBase.stock_num}</td>
                                                    <td class="center">${plantBase.real_sale_num}</td>
                                                    <td class="center">${plantBase.equity_cycle}</td>
                                                    <td class="center">${plantBase.start_time}</td>
                                                    <td class="center">${plantBase.end_time}</td>
                                                    <td class="center"><c:if test="${plantBase.sale_type=='01'}">售卖中</c:if><c:if test="${plantBase.sale_type=='00'}">已售馨</c:if></td>
                                                    <td class="center"><c:if test="${plantBase.state=='01'}">已上架</c:if><c:if test="${plantBase.state=='00'}">已下架</c:if></td>
                                                    <td class="center">
                                                    <c:if test="${plantBase.state=='01'}">
                                                    	<a class="btn btn-xs btn-success" title="下架"
														onclick="editMealState('${plantBase.id}','00','${plantBase.end_time }')"> <i
														class="ace-icon fa fa-lock bigger-120"
														title="下架"></i>
													</a> 
													<a class="btn btn-xs btn-success" title=" 套餐商品"
                                                            onclick="addGoods('${plantBase.id}','01');">
                                                            	  套餐商品
                                                         </a>
                                                         <c:if test="${plantBase.sale_type =='01' }">
                                                      <a  class="btn btn-xs btn-success" href="javascript:;"
                                                        onclick="editSaleType('${plantBase.id}','00')"> 
                                                                                                                                                  售馨
                                                      </a>
                                                    </c:if>
                                                    <c:if test="${plantBase.sale_type =='00' }">
                                                      <a href="javascript:;" class="btn btn-xs btn-success"
                                                        onclick="editSaleType('${plantBase.id}','01')"> 
                                                                                                                                                 售卖                                                                                    
                                                      </a>
                                                    </c:if>
                                                    </c:if>
                                                     <c:if test="${plantBase.state=='00'}">
                                                    
                                                    	<c:if test="${QX.edit == 1 }">
                                                    	 <a class="btn btn-xs btn-success" title="上架"
															onclick="editMealState('${plantBase.id}','01','${plantBase.end_time }')"> <i
															class="ace-icon fa fa-unlock bigger-120"
															title="上架"></i>
														</a>
                                                            <a class="btn btn-xs btn-success" title="编辑"
                                                               onclick="editMeal('${plantBase.id}');">
                                                                <i class="ace-icon fa fa-pencil-square-o bigger-120"
                                                                   title="编辑"></i>
                                                            </a>
                                                        </c:if>
														 <a class="btn btn-xs btn-success" title="套餐商品"
                                                            onclick="addGoods('${plantBase.id}','00');">
                                                            	 套餐商品
                                                         </a>
                                                    </c:if>
                                                    </td>
                                                </tr>
                                            </c:forEach>
                                        </c:if>
                                        <c:if test="${QX.cha == 0 }">
                                            <tr>
                                                <td colspan="100" class="center">您无权查看</td>
                                            </tr>
                                        </c:if>
                                    </c:when>
                                    <c:otherwise>
                                        <tr class="main_info">
                                            <td colspan="100" class="center">没有相关数据</td>
                                        </tr>
                                    </c:otherwise>
                                </c:choose>
                                </tbody>
                            </table>

                            <div class="page-header position-relative">
                                <table style="width: 100%;">
                                    <tr>
                                        <td style="vertical-align:top;">
                                            <c:if test="${QX.add == 1 }">
                                                <a class="btn btn-mini btn-success" onclick="add();">新增</a>
                                            </c:if>
                                        </td>
                                        <td style="vertical-align: top;">
                                        </td>
                                        <td style="vertical-align: top;">
                                            <div class="pagination"
                                                 style="float: right; padding-top: 0px; margin-top: 0px;">${page.pageStr}</div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </form>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up"
       class="btn-scroll-up btn btn-sm btn-inverse"> <i
            class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div>
<!-- /.main-container -->
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../../system/index/foot.jsp" %>
<!-- 删除时确认窗口 -->
<script src="static/ace/js/bootbox.js"></script>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>
<!-- 日期框 -->
<script src="static/ace/js/date-time/bootstrap-datepicker.js"></script>
<!-- 下拉框 -->
<script src="static/ace/js/chosen.jquery.js"></script>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</body>
<script type="text/javascript">
    $(top.hangge());
    $(function () {
        //复选框全选控制
        var active_class = 'active';
        $('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function () {
            var th_checked = this.checked;//checkbox inside "TH" table header
            $(this).closest('table').find('tbody > tr').each(function () {
                var row = this;
                if (th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
                else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
            });
        });
    });

    //检索
    function searchs() {
        top.jzts();
        $("#plantbaseForm").submit();
    }

    //新增
    function add() {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "新增套餐";
        diag.URL = '<%=basePath%>setMeal/goAddMeal.do';
        diag.Width = 1150;
        diag.Height = 700;
        diag.CancelEvent = function () { //关闭事件
        	if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
    			nextPage('${page.currentPage}');
    		}
    		diag.close();
    	 };
    	 diag.show();
    }
    	
    function editSaleType(id,state){
		$.get("<%=basePath%>setMeal/updateSaleState.do",{
			         id:  id,
			        state:   state,
			        },function(data){
			        //这里显示从服务器返回的数据
			       if("success"==data){
			    	   alert("修改成功");
			       }else if("failed"==data){
			    	   alert("修改失败");
			       }
			        nextPage('${page.currentPage}');
			    });	
	}

    // 编辑
    function editMeal(id) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "修改套餐";
        diag.URL = '<%=basePath%>setMeal/goEditMeal.do?id='+id;
        diag.Width = 1150;
        diag.Height = 700;
        diag.CancelEvent = function () { //关闭事件
        	if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
    			nextPage('${page.currentPage}');
    		}
    		diag.close();
    	 };
    	 diag.show();
    }
    
	function addGoods(id,state){
	     top.jzts();
	     var diag = new top.Dialog();
	     diag.Drag = true;
	     diag.Title = "套餐商品列表";
	     diag.URL = '<%=basePath%>setMeal/goMealGoods.do?id='+id+'&state='+state;
	     diag.Width = 1000;
	     diag.Height = 550;
	     diag.CancelEvent = function () { //关闭事件
	    	 window.location.href='<%=basePath%>setMeal/list.do';
	        	diag.close();
	 	 };
	 	 diag.show();
	 }
    
    function delBase(id){
    	var baseId=$("#baseId").val();
        bootbox.confirm("确定要删除此地址吗?", function(result) {
            if(result) {
                top.jzts();
                var url = "<%=basePath%>plantbase/deleteD?id="+id;
                $.get(url,function(data){
                    if(data=="success"){
                    }else{
                        alert("删除失败");
                    }
                    window.location.href='<%=basePath%>plantbase/goDeliveryList.do?id='+baseId;
                });
            }
        });
    }

  //修改上下架状态
    function editMealState(id,state,endTime){
    	$.get("<%=basePath%>setMeal/updateMealState.do",{
    		         id:  id,
    		        state:   state,
    		        endTime: endTime,
    		        },function(data){
    		        //这里显示从服务器返回的数据
    		       if("success"==data){
    		    	   alert("修改成功");
    		       }else if("failed"==data){
    		    	   alert("修改失败");
    		       }else if("timeEnd"==data){
    		    	   alert("此商品下架时间已到!");
    		       }else if("no-goods"==data){
    		    	   alert("此套餐还未添加商品!");
    		       }
    		        nextPage('${page.currentPage}');
    		    });	
    }
    
</script>
</html>
